Add integration test for dry running Agents

Dominik Sander 7 years ago
parent
commit
f1e554cfff
1 changed files with 41 additions and 0 deletions
  1. 41 0
      spec/features/dry_running_spec.rb

+ 41 - 0
spec/features/dry_running_spec.rb

@@ -1,6 +1,7 @@
1 1
 require 'rails_helper'
2 2
 
3 3
 describe "Dry running an Agent", js: true do
4
+  let(:agent)   { agents(:bob_website_agent) }
4 5
   let(:formatting_agent) { agents(:bob_formatting_agent) }
5 6
   let(:user)    { users(:bob) }
6 7
   let(:emitter) { agents(:bob_weather_agent) }
@@ -16,6 +17,35 @@ describe "Dry running an Agent", js: true do
16 17
   end
17 18
 
18 19
   context 'successful dry runs' do
20
+    before do
21
+      stub_request(:get, "http://xkcd.com/").
22
+        with(:headers => {'Accept-Encoding'=>'gzip,deflate', 'User-Agent'=>'Huginn - https://github.com/cantino/huginn'}).
23
+        to_return(:status => 200, :body => File.read(Rails.root.join("spec/data_fixtures/xkcd.html")), :headers => {})
24
+    end
25
+
26
+    it 'shows the dry run pop up without previous events and selects the events tab when a event was created' do
27
+      open_dry_run_modal(agent)
28
+      click_on("Dry Run")
29
+      expect(page).to have_text('Biologists play reverse')
30
+      expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
31
+    end
32
+
33
+    it 'shows the dry run pop up with previous events and allows use previously received event' do
34
+      emitter.events << Event.new(payload: {url: "http://xkcd.com/"})
35
+      agent.sources << emitter
36
+      agent.options.merge!('url' => '', 'url_from_event' => '{{url}}')
37
+      agent.save!
38
+
39
+      open_dry_run_modal(agent)
40
+      find('.dry-run-event-sample').click
41
+      within(:css, '.modal .builder') do
42
+        expect(page).to have_text('http://xkcd.com/')
43
+      end
44
+      click_on("Dry Run")
45
+      expect(page).to have_text('Biologists play reverse')
46
+      expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
47
+    end
48
+
19 49
     it 'sends escape characters correctly to the backend' do
20 50
       emitter.events << Event.new(payload: {data: "Line 1\nLine 2\nLine 3"})
21 51
       formatting_agent.sources << emitter
@@ -32,4 +62,15 @@ describe "Dry running an Agent", js: true do
32 62
       expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
33 63
     end
34 64
   end
65
+
66
+  it 'shows the dry run pop up without previous events and selects the log tab when no event was created' do
67
+    stub_request(:get, "http://xkcd.com/").
68
+      with(:headers => {'Accept-Encoding'=>'gzip,deflate', 'User-Agent'=>'Huginn - https://github.com/cantino/huginn'}).
69
+      to_return(:status => 200, :body => "", :headers => {})
70
+
71
+    open_dry_run_modal(agent)
72
+    click_on("Dry Run")
73
+    expect(page).to have_text('Dry Run started')
74
+    expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabLog"]')
75
+  end
35 76
 end